package com.douding.business.controller.admin;

import com.douding.server.domain.Teacher;
import com.douding.server.dto.TeacherDto;
import com.douding.server.dto.PageDto;
import com.douding.server.dto.ResponseDto;
import com.douding.server.service.TeacherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/teacher")
public class TeacherController {

    private static final Logger LOG = LoggerFactory.getLogger(TeacherController.class);
    // 给了日志用的
    public static final String BUSINESS_NAME = "讲师";

    @Resource
    private TeacherService teacherService;

    @RequestMapping("/list")
    public ResponseDto list(PageDto pageDto) {
        ResponseDto responseDto = new ResponseDto();
        teacherService.selectByPage(pageDto);
        responseDto.setContent(pageDto);
        return responseDto;
    }

    // 新增课程中需要的讲师列表
    @RequestMapping("/all")
    public ResponseDto all() {
        ResponseDto responseDto = new ResponseDto();
        List<Teacher> teacherList = teacherService.selectList();
        responseDto.setContent(teacherList);
        return responseDto;
    }

    @PostMapping("/save")
    public ResponseDto save(@RequestBody TeacherDto teacherDto) {
        teacherService.save(teacherDto);
        boolean flag = teacherDto.getId() == null;
        return flag ? ResponseDto.saveSuccess() : ResponseDto.updateSuccess();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable String id) {
        teacherService.deleteById(id);
        return ResponseDto.success();
    }

}
